
package com.treeman.navi.marker.ballon;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.android.maps.OverlayItem;
import com.treeman.navi.R;
import com.treeman.navi.marker.MarkerItem;


public class CustomBalloonOverlayView<Item extends OverlayItem> extends BalloonOverlayView<MarkerItem>
{

    private Context context;

    private TextView title;
    private TextView snippet;
    private ImageView image;

    private View view;


    public CustomBalloonOverlayView(Context context, int balloonBottomOffset)
    {
	super(context, balloonBottomOffset);
	this.context = context;
    }

    @Override
    protected void setupView(Context context, final ViewGroup parent)
    {
	// inflate our custom layout into parent
	LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	view = inflater.inflate(R.layout.custom_balloon_overlay, parent);

	// setup our fields
	title = (TextView) view.findViewById(R.id.balloon_item_title);
	snippet = (TextView) view.findViewById(R.id.balloon_item_snippet);
	// image = (ImageView) v.findViewById(R.id.balloon_item_image);

	// implement balloon close
	ImageView close = (ImageView) view.findViewById(R.id.balloon_close);
	close.setOnClickListener(new OnClickListener()
	{

	    public void onClick(View v)
	    {
		parent.setVisibility(GONE);
	    }
	});

    }

    @Override
    protected void setBalloonData(MarkerItem item, ViewGroup parent)
    {

	// map our custom item data to fields
	title.setText(item.getTitle());
	snippet.setText(item.getSnippet());

    }

    public void setImage(int id)
    {
	image = (ImageView) view.findViewById(id);
    }

}
